"""
  浏览一个需要登录才能看见的url
  1）请求头从包括cookie信息
    F12-network 找到请求头user-agent、cookie
  2）cookies参数
"""

import requests

#1)
url='https://gitee.com/'

h={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
    'Cookie': 'user_locale=zh-CN; oschina_new_user=false; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1605765798; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%228076208%22%2C%22first_id%22%3A%22175df19986c6ac-0758413173a902-333769-2073600-175df19986dbc3%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%22175df19986c6ac-0758413173a902-333769-2073600-175df19986dbc3%22%7D; Hm_lpvt_24f17767262929947cc3631f99bfd274=1605765820; gitee-session-n=c0xzWlBVSHIxNzE0OWN2UVQ3NjhKMFJTZU5aVlM5eWJyMGozdndnYm1VUkt5cE5IaER1dWZPb09QWXh3TWliVW9FQklLdFV0SExxY2t6MVdyVFIzNzVjVDJxNHJKRXg3SWdCcG5HUUtXUUpnaEdTT0VQZGNiRWhYaFZHZUxKeng0VVl4Q1p1YzBKbXc3eFpqSU5UcU9sY2lVbFZWaXlJRm1HL0NFbllNeWc2b3RaZ0pZMG9yeEhabXQrcHB2VnpvNk5ocXZaSndTMUJzTXRTYlNlZysyYVJQM0Z2a2RRc2FZL29zb0VIMXJPckIwN1lLQVBYeVZlWXRNUHNPYlFWeG5HMkgwTUU0NHdlaGFuVzFlVE5sSE5WZHM4RXdnK1BaeHdlb3RhVVhEOFQreW9ldjVYbEdBb2o4OEdNQWY1SlJjN1M5dFpZZDFkeUJrQlFyKzhUQjE4SkxEUHE3OW5RZFgrdEk5YSsxNEJnPS0taWh3cG9sQW5yLzlHNjVTTlpSRFlyUT09--ce3f32412f56dd7ea87ff3a572181581a8f407df'
}

r=requests.get(url,h)
print(r.content.decode())

print('*'*20)
print('*'*20)

#2)

h={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
}

str_cookies='Cookie: user_locale=zh-CN; oschina_new_user=false; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1605765798; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%228076208%22%2C%22first_id%22%3A%22175df19986c6ac-0758413173a902-333769-2073600-175df19986dbc3%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%22175df19986c6ac-0758413173a902-333769-2073600-175df19986dbc3%22%7D; Hm_lpvt_24f17767262929947cc3631f99bfd274=1605765820; gitee-session-n=c0xzWlBVSHIxNzE0OWN2UVQ3NjhKMFJTZU5aVlM5eWJyMGozdndnYm1VUkt5cE5IaER1dWZPb09QWXh3TWliVW9FQklLdFV0SExxY2t6MVdyVFIzNzVjVDJxNHJKRXg3SWdCcG5HUUtXUUpnaEdTT0VQZGNiRWhYaFZHZUxKeng0VVl4Q1p1YzBKbXc3eFpqSU5UcU9sY2lVbFZWaXlJRm1HL0NFbllNeWc2b3RaZ0pZMG9yeEhabXQrcHB2VnpvNk5ocXZaSndTMUJzTXRTYlNlZysyYVJQM0Z2a2RRc2FZL29zb0VIMXJPckIwN1lLQVBYeVZlWXRNUHNPYlFWeG5HMkgwTUU0NHdlaGFuVzFlVE5sSE5WZHM4RXdnK1BaeHdlb3RhVVhEOFQreW9ldjVYbEdBb2o4OEdNQWY1SlJjN1M5dFpZZDFkeUJrQlFyKzhUQjE4SkxEUHE3OW5RZFgrdEk5YSsxNEJnPS0taWh3cG9sQW5yLzlHNjVTTlpSRFlyUT09--ce3f32412f56dd7ea87ff3a572181581a8f407df'

dict_cookies={cookie.split('=')[0]:cookie.split('=')[1] for cookie in str_cookies.split(';')}
r=requests.get(url,h,cookies=dict_cookies)
print(r.content.decode())







